package slot_machine

import (
	"longmen/server/pkg/common/api_models"
	"sync"
	"time"
)

const (
	STATE_PREPARE  = 1 // 准备开始阶段
	STATE_ACTION   = 2 // 行动阶段(玩家下注)
	STATE_SHOWDOWN = 3 // 亮牌阶段(赔付)
	STATE_PAUSE    = 4 // 暂停阶段

	PrepareTime    = 2  // 准备时间(秒)
	ActionTime     = 50 // 下注时间(秒)
	SettlementTime = 5  // 结算时间

)

// gameStart
func (t *SlotTable) gameStart() {
	t.prepareGame()
}

// prepareGame 准备游戏
func (t *SlotTable) prepareGame() {
	t.changeState(STATE_PREPARE)
	t.handBeginTime = time.Now().Unix()

	t.broadcastMsg(STATE_PREPARE, api_models.GamePrepareBroadcast{
		Countdown: PrepareTime,
		BeginTime: t.handBeginTime,
	})

	t.gameInit()
	t.timer.Start(PrepareTime*time.Second, t.startAction)
}

// gameInit 游戏初始化
func (t *SlotTable) gameInit() {
	var pots sync.Map
	for i := 0; i < 8; i++ {
		pots.Store(i, 0)
	}
	t.stopAction = false
	t.potBet = pots
	t.gameNum++
}

// startAction  开始行动  下注阶段
func (t *SlotTable) startAction() {
	t.changeState(STATE_ACTION)
	t.broadcastMsg(STATE_ACTION, api_models.GameBetBroadcast{
		Countdown: ActionTime,
	})
	t.timer.Start(ActionTime*time.Second, t.gameSettlement)
}

// gameSettlement 游戏结算
func (t *SlotTable) gameSettlement() {
	t.stopAction = true
	t.changeState(STATE_SHOWDOWN)
	t.timer.Start(SettlementTime*time.Second, t.gameEnd)
}

// gameSettlement 游戏结束
func (t *SlotTable) gameEnd() {

}
